package algorithm.beforestart.primary.str;

public class reverseString {

    public static void reverseString(char[] s) {
        int n=s.length;
        int left =0;int right=n-1;
        while (right>=left){
            swap(s,left,right);
            left++;
            right--;
        }
    }

    public static void reverseString2(char[] s) {
        int n=s.length;
        int left =0;int right=n-1;

            reverseString3(s,left,right);

    }

    private static void reverseString3(char[] s, int left, int right) {
        if (right<=left){
            return;
        }
        reverseString3(s,left+1,right-1);
        swap(s,left,right);


    }


    private static void swap(char[] s, int left, int right) {
        Character temp =s[left];
        s[left] =s[right];
        s[right]=temp;
    }


    public static void main(String[] args) {
        char[] s={'h','e','l','l','o'};
        reverseString2(s);

        for(int i=0;i<s.length;i++){
            System.out.println(s[i]);
        }
    }
}
